import entity.Regions;
import utils.DButils;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Demo1 {
    public static void main(String[] args) {
        String sql="select * from Regions";
        try {
            ResultSet rs= DButils.query( sql );
            List<Regions>regions=new ArrayList();
           while (rs.next()){
               regions.add( new Regions(  rs.getInt( 1 ),rs.getString( 2 )));
           }
           rs.close();
           for (Regions r:regions){
               System.out.println(r);
           }
        } catch (SQLException e) {
            e.printStackTrace();
        }
       /* try {
            //加载驱动
            Class.forName( "oracle.jdbc.driver.OracleDriver" );
            System.out.println("驱动加载成功");
            String url="jdbc:oracle:thin:@localhost:1521:xe";
            String user="hr";
            String pwd="123";
           // 获取连接
            Connection connection=DriverManager.getConnection( url,user,pwd );
            System.out.println("连接数据成功");
         *//*  // String sql="insert into regions (region_id,region_name)values(6,'北极')";
            String  sql="select * from regions";
            //执行器创建statement
           Statement statement=connection.createStatement();
            ResultSet resultSet=statement.executeQuery( sql );
            while (resultSet.next()){
                System.out.print(resultSet.getInt( 1 )+"\t"+resultSet.getString( 2 ));
                System.out.println();
            }
            *//*
         //or映射
         String sql="select*from regions";
         Statement statement=connection.createStatement();
         ResultSet resultSet=statement.executeQuery( sql );
            List<Regions>regions=new ArrayList<>(  );
         while (resultSet.next()){
             Regions r =new Regions();
            r.setRegionsId(resultSet.getInt( "region_id" ));
            r.setRegionsName( resultSet.getString( "region_name" ) );
            regions.add( r );
          //regions.add( new Regions( resultSet.getInt( 1 ),resultSet.getString( 2 ) ) );
         }
         for (Regions r:regions){
             System.out.println(r);
         }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();


    }*/
    }
}